package com.sright.bcard.enterprise.biz.service;

import com.sright.bcard.common.service.share.dto.enterprise.AllAvatarDTO;
import com.sright.bcard.common.service.share.dto.enterprise.AllMaterialDTO;
import com.sright.bcard.common.service.share.dto.page.BetweenDateParamRequest;
import com.sright.bcard.common.service.share.dto.page.PageParamRequest;
import com.sright.bcard.common.service.share.dto.pager.Pager;
import com.sright.bcard.common.service.share.dto.page.PageDTO;
import com.sright.bcard.common.service.share.utils.DataConvertUtils;
import com.sright.bcard.content.dal.entity.MaterialDO;
import com.sright.bcard.enterprise.biz.manager.MaterialManager;
import com.sright.bcard.common.service.share.dto.enterprise.MaterialDTO;
import com.sright.bcard.enterprise.share.response.MaterialResponse;
import com.sright.bcard.enterprise.share.service.MaterialService;
import com.sright.common.response.SrightResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class MaterialServiceImpl implements MaterialService {

    @Autowired
    private MaterialManager materialManager;

    @Override
    public Pager<AllMaterialDTO> pageList(Integer materialType,
                                          BetweenDateParamRequest betweenDateParamRequest,
                                          PageParamRequest pageParamRequest, Integer needReview) {
        return materialManager.pageList(materialType, betweenDateParamRequest, pageParamRequest,needReview);
    }

    @Override
    public Pager<AllAvatarDTO> avatarList(PageParamRequest paramRequest, Integer needReview) {
        return materialManager.avatarList(paramRequest,needReview);
    }

    @Override
    public void deleteAvatar(Long id) {
        materialManager.deleteAvatar(id);
    }

    @Override
    public Pager<MaterialDTO> pageListOfCardUserInfo(Integer cardType, Integer checkStatus, BetweenDateParamRequest betweenDateParamRequest, PageParamRequest request) {
        return null;
    }

    @Override
    public SrightResponse<Long> addMaterial(MaterialDTO materialDTO) {
        return SrightResponse.defaultSuccess(materialManager.addMaterial(materialDTO));
    }

    @Override
    public SrightResponse<PageDTO<MaterialResponse>> list(MaterialDTO materialDTO) {
        PageDTO<MaterialResponse> pageDTO = new PageDTO<>();
        // 获取企业id
        List<MaterialDO> list = materialManager.list(materialDTO);
        // DO 转化为 DTO
        List<MaterialResponse> materialResponses = new ArrayList<>();
        DataConvertUtils.convertDOList2DTOList(list, materialResponses, MaterialResponse.class);
        if(CollectionUtils.isNotEmpty(list)) {
            pageDTO.setCount(materialResponses.size());
            pageDTO.setData(materialResponses);
        }
        return SrightResponse.defaultSuccess(pageDTO);
    }

    @Override
    public SrightResponse<Integer> editMaterial(MaterialDTO materialDTO) {
        return SrightResponse.defaultSuccess(materialManager.editMaterial(materialDTO));
    }

    @Override
    public Integer deleteMaterial(Long id) {
        return materialManager.deleteMaterial(id);
    }

    @Override
    public SrightResponse<List<MaterialDTO>> personalMaterialList(MaterialDTO materialDTO) {
        return SrightResponse.defaultSuccess(materialManager.personalMaterialList(materialDTO));
    }

    @Override
    public SrightResponse addPersonalMaterial(MaterialDTO materialDTO) {
        return SrightResponse.defaultSuccess(materialManager.addPersonalMaterial(materialDTO));
    }

    @Override
    public SrightResponse<Boolean> editPersonalMaterial(List<Long> ids,Long userId) {
        return SrightResponse.defaultSuccess(materialManager.editPersonalMaterial(ids,userId));
    }

    @Override
    public SrightResponse<Integer> deletePersonalMaterial(List<Long> ids) {
        return SrightResponse.defaultSuccess(materialManager.deletePersonalMaterial(ids));
    }

    @Override
    public SrightResponse<PageDTO<MaterialResponse>> page(MaterialDTO materialDTO) {
        return SrightResponse.defaultSuccess(materialManager.page(materialDTO));
    }
}
